<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>库存期初建账管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
		
			$("#check_ok").click(function(){
				//获取所有的选择列
				var data=[];
				$("#contentTable").find(":checkbox:checked").each(function(key,value){
				 	var $tr = $(this).parent().parent().parent();
				 	var tds = $tr.find("td");
					var tr = {
						id : "",
						index : guid(),
						productId : $(tds[10]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						batchnoId : $(tds[13]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						name : $(tds[1]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						sort : $(tds[15]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						companyName : $(tds[3]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						batchno : $(tds[4]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						spec : $(tds[5]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						dose : $(tds[6]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						storenum : $(tds[9]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						//storenumK : $(tds[14]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						storenumF : $(tds[16]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						vaccExpDate : $(tds[7]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						orignprice : $(tds[8]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						sellprice : $(tds[12]).text().replace(/[\r\n]/g, "").replace( /(^\s*)|(\s*$)/g, ""),
						num : ''
					}
					data.push(tr);
				});
				if(data.length==0){
					layer.msg("至少选择一条记录",{"icon":7, "time":1000});
					return ;
				}
				parent.layer.closeAll();
				parent.layerDiv(data);
			});
			
			$("#reset").click(function(){
				reset();
			});
			
		});

		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		var bsProduct = JSON.parse('${fns:toJson(bsProduct)}');
		function finishVaccine2Company(){
			if(bsProduct && bsProduct["vaccineId"]){
		       $("#vaccineId").val(bsProduct.vaccineId);
			   $("#vaccineId").select2();
			   $("#vaccineId").change();
			}
		}
		function finishSelectCompany(){
			$("#companyCode").val(bsProduct.companyCode);
			$("#companyCode").select2();
		}
		function reset(){
			$("#bsVaccineBatchno-batchType").val("").select2();
		 	$('#vaccineId').val("").select2();
		 	$('#companyCode').val("").select2();
		 	$('#batchno').val("");
		 	$('#cType').val("").select2();
		 	$("input[name=beginVaccExpDate]").val("");
		 	$("input[name=endVaccExpDate]").val("");
		} 
	</script>

	<style type="text/css">
		body{
			padding:10px;
		}
		.minWidth {
			min-width: 177px;
		}	
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/vaccinate/bsProduct/">库存列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="bsProduct" action="${ctx}/vaccinate/bsProduct/findListByStoreNumAndOutBoundDate" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<div class="breadcrumb">
			<table class="table table-bordered">
				<tr>
				    <th>疫苗/注射器：</th>
					<td>
						<form:select path="bsVaccineBatchno.batchType" id="bsVaccineBatchno-batchType" class="span2 minWidth">
							<form:option value="" label="--请选择--"/>
							<form:options items="${fns:getDictList('batch_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select> 
					</td>
				    <th>疫苗类型：</th>
					<td>
						<form:select path="cType" id="cType" class="span2 minWidth">
							<form:option value="" label="--请选择--"/>
							<form:options items="${fns:getDictList('bs_vaccineInfo_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select> 
					</td>
					<th>疫苗名称:</th>
					<td>
						<form:select path="vaccineId" id="vaccineId" class="span2 minWidth vaccine2Company" >
							<form:option value=""  label="--请选择--"/>
						</form:select>
					</td>
					<th>生产企业：</th>
					<td>
						<form:select path="companyCode" id="companyCode" class="span2 minWidth selectCompany">
							<form:option value="" label="--请选择--"/> 
						</form:select>
					</td>
				</tr>
				<tr>
				    <th>疫苗批号：</th>
					<td>
						<form:input path="batchno" id="batchno" class="span2 minWidth" />	
					</td>
					<th>起始有效期：</th>
					<td>
						<input name="beginVaccExpDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${bsProduct.beginVaccExpDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
					</td>
					<th>截止有效期：</th>
					<td colspan="3">
						<input name="endVaccExpDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${bsProduct.endVaccExpDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
					</td>
				</tr>
			</table>
		</div>
		<div>
			<button id="btnSubmit" class="btn btn-primary" type="submit">查询</button>
			<button id="reset"  class="btn btn-primary" type="button">重置</button>
			<button id="check_ok" class="btn btn-primary"  type="button">确认选择</button>
		</div>
	</form:form>
	
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>选择</th>
				<th>疫苗名称</th>
				<th>疫苗属性</th>
				<th>疫苗生产企业</th>
				<th>批号</th>
				<th>规格(剂/支或粒)</th>
				<th>剂量</th>
				<th>有效期</th>
				<th>成本价</th>
				<th>库存数量(支或粒)</th>
				<th>可用库存</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="bsProduct">
			<tr data-data='${fns:toJson(bsProduct) }'>
				<td>
					<input type="checkbox">
				</td>
				<td>
					${bsProduct.bsVaccineBatchno.vaccineName}<input type="hidden" name="p_id" value="${bsProduct.id}">
				</td>
				<td>
					${fns:getDictLabel(bsProduct.cType, "bs_vaccine_type", "")}
				</td>
				<td>
					${bsProduct.bsVaccineBatchno.companyName}
				</td>
				<td>
					${bsProduct.bsVaccineBatchno.batchno}
				</td>
				<td>
					${bsProduct.bsVaccineBatchno.spec}
				</td>
				<td>
					${bsProduct.bsVaccineBatchno.dose}
				</td>
				<td>
					<fmt:formatDate value="${bsProduct.bsVaccineBatchno.outBoundDate}" pattern="yyyy-MM-dd"/>
				</td>
				<td>
					${bsProduct.orignprice}
				</td>
				<td>
					${bsProduct.storenum}
				</td>
				<td style="display:none">
					${bsProduct.id}
				</td>
				<td style="display:none">
					${bsProduct.orignprice}
				</td>
				<td style="display:none">
					${bsProduct.sellprice}
				</td>
				<td style="display:none">
					${bsProduct.bsVaccineBatchno.id}
				</td>
				<td>
					${bsProduct.storenum-bsProduct.storenumF}
				</td>
				<td style="display:none">
					${bsProduct.cType}
				</td>
				<td style="display:none">
					${bsProduct.storenumF}
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>